-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rust axum guide #6783
base: master
Are you sure you want to change the base?
Rust axum guide #6783
Conversation
Would like to see some good practices for organaizing structs / code / files when there are a bunch of queries that shares similiar |
Something really comprehensive might turn this from a quick guide into something else but have added two tips off the top of my head that fit with the Open-Meteo output: |
Let's say I want to return Json directly without using serde. How can I do it? |
impl IntoResponse for edb_model::Json {
fn into_response(self) -> axum::response::Response {
(
[(
axum::http::header::CONTENT_TYPE,
"application/json".parse::<axum::http::HeaderValue>().unwrap(),
)],
self.to_string(),
)
}
} only traits defined in the current crate can be implemented for types defined outside of the crate Something like this can help: struct EdgedbJson(edb_model::Json);
impl IntoResponse for EdgedbJson {
fn into_response(self) -> axum::response::Response {
let mut response = Response::new(self.0.to_string().into());
response.headers_mut().append(
axum::http::header::CONTENT_TYPE,
"application/json".parse::<axum::http::HeaderValue>().unwrap(),
);
response
}
} |
No description provided.